package com.im.handler;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
import io.netty.handler.stream.ChunkedWriteHandler;

public class WebSocketInitHandler extends ChannelInitializer<SocketChannel> {


  @Override
  protected void initChannel(SocketChannel socketChannel) throws Exception {
   ChannelPipeline pipeline = socketChannel.pipeline();
   //解码器
   pipeline.addLast(new HttpServerCodec());
   //自定义处理类
//   pipeline.addLast("customerHander",new CustomerHandler());
   //为大数据传输提供支持
   pipeline.addLast(new ChunkedWriteHandler());
   //自定义webSocket
   pipeline.addLast(new HttpObjectAggregator(2048*64));
   //定义请求url
   pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
   //传递给后端的 自己处理的hander
   pipeline.addLast(new ChatHander());

  }
}
